package com.aispeech.aicube.robot;

import android.util.Log;

import com.catalinjurjiu.rubikdetector.RubikDetectorUtils;
import com.catalinjurjiu.rubikdetector.model.RubikFacelet;

public class MyVision {
    private final String TAG = "MyVision";

    private EyesListener mListener;

    public MyVision() {
    }

    public void open(EyesListener listener) {
        mListener = listener;
    }

    public void close() {

    }

    public void versionDirectionChange(int direction) {
        Log.d(TAG, "versionDirectionChange() called with: direction = [" + direction + "]");
        if (null == mListener) {
            return;
        }
    }


    public void seeCube(RubikFacelet[][] facelets) {
        if (null != mListener) {
            String resultColorsAsString = RubikDetectorUtils.getResultColorsAsString(facelets);
//            Log.d(TAG, "seeCube() called with: result = [" + resultColorsAsString + "]");
            StringBuilder stringBuilder = new StringBuilder();

            for (int i = 0; i < 3; i++) {
                for (int j = 0; j < 3; j++) {
                    switch (facelets[i][j].color) {
                        case RubikFacelet.Color.WHITE:
                            stringBuilder.append("WHITE:");
                            break;
                        case RubikFacelet.Color.YELLOW:
                            stringBuilder.append("YELLOW:");
                            break;
                        case RubikFacelet.Color.RED:
                            stringBuilder.append("RED:");
                            break;
                        case RubikFacelet.Color.BLUE:
                            stringBuilder.append("BLUE:");
                            break;
                        case RubikFacelet.Color.GREEN:
                            stringBuilder.append("GREEN:");
                            break;
                        case RubikFacelet.Color.ORANGE:
                            stringBuilder.append("ORANGE:");
                            break;
                    }
                }
            }
            mListener.onSee(stringBuilder.toString());
        }
    }

    public interface EyesListener {
        void onSee(String things);
    }
}